package org.reliablesource.prism.ui.workbench.actions;

/**
 *  
 *  Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved
 *
 *	Created on: Mar 15, 2006
 *  @author Dennis Park <a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 */

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.reliablesource.prism.ui.actions.CaptureScreenAction;

/**
 * Our sample action implements workbench action delegate.
 * The action proxy will be created by the workbench and
 * shown in the UI. When the user tries to use the action,
 * this delegate will be created and execution will be 
 * delegated to it.
 * @see IWorkbenchWindowActionDelegate
 */
public class CaptureWindowAction implements IWorkbenchWindowActionDelegate{
	
	private CaptureScreenAction captureScreenAction;
	private IWorkbenchWindow window;
	
	/**
	 * The constructor.
	 */
	public CaptureWindowAction() {
		captureScreenAction = new CaptureScreenAction();
	}

	/**
	 * @see IWorkbenchWindowActionDelegate#run
	 */
	public void run(IAction action) {
		if(window == null)
			return;
		
		captureScreenAction.setChecked(!captureScreenAction.isChecked());
		captureScreenAction.run();
	}

	/**
	 * Selection in the workbench has been changed. We 
	 * can change the state of the 'real' action here
	 * if we want, but this can only happen after 
	 * the delegate has been created.
	 * @see IWorkbenchWindowActionDelegate#selectionChanged
	 */
	public void selectionChanged(IAction action, ISelection selection) {
	}

	/**
	 * We can use this method to dispose of any system
	 * resources we previously allocated.
	 * @see IWorkbenchWindowActionDelegate#dispose
	 */
	public void dispose() {
		if(captureScreenAction != null)
			captureScreenAction.dispose();
	}

	/**
	 * We will cache window object in order to
	 * be able to provide parent shell for the message dialog.
	 * @see IWorkbenchWindowActionDelegate#init
	 */
	public void init(IWorkbenchWindow _window) {
		window = _window;
		captureScreenAction.init();
	}
}